//页面数据初始化
    var status=initData.status;
	if(status=="01"){
		$("#submit").html("即将开始").css("background","#ccc");
		buyStop=true;
	}
	var endTime=new Date(initData.endTime);
	var today=new Date();
	var lastTime=endTime-today;
	if(lastTime<0){
		$("#submit").css("background","#ccc").html("已结束");
		buyStop=true;
	}

/*//初始化未来30天的日期，并加入到select中
     var Week = ['日','一','二','三','四','五','六'];
	 var endDate=new Date(initData.endTime);
	 var current=new Date();
	 var showDate=parseInt((endDate-current)/(1000*60*60*24))+1;
     function getNextDay(i){
        var d = new Date();
        d = +d + 1000*60*60*24*i;
        d = new Date(d);
		var c=d.getDay();
		var y=d.getFullYear();

		var a=String(d.getMonth()+1)
		if (a.length==1){
			a="0"+a;
			}
		var b=String(d.getDate());
		if(b.length==1){
			b="0"+b;
			}
		return (y+"年"+a+"月"+b+"日"+" 星期"+Week[c]); 
        }
		
     for(var i=0;i<showDate;++i){
         var node1 = document.createElement("option");
		 node1.innerHTML=getNextDay(i);
		 document.getElementById("date").appendChild(node1)	
	    } 
     $("#dateSpan").html($("#date option:selected").val())
//选择时间

	  $("#date").change(function(){	  
		    var date=$('#date option:selected').val(); 
			$("#dateSpan").html(date);
	  })*/
 //用户增加或者减少用餐人数的操作
       $(".reduceButton").click(function(e) {
        e.cancelBubble=true; 
	   e.stopPropagation();
    });
	$(".addButton").click(function(e) {
      e.cancelBubble=true; 
	   e.stopPropagation(); 
    });
       $(".reduceButton").bind("touchstart",function(e){ 
	       
	       $(this).find("img").attr("src",styleUrl+"/styles/img/reduceIconHover.png");  
	       var peopleNum=Number($(this).siblings(".buyNumber").val()); 
		   if(peopleNum==0){
		     commonTckBlack("购买数量不能小于0");
			 $(this).siblings(".buyNumber").val(0);
			 return;
		    }
			peopleNum=Number(peopleNum)-1;
			$(this).siblings(".buyNumber").val(peopleNum);
		  totalPrice();
		  },false)
	   $(".reduceButton").bind("touchend",function(e){
		    $(this).find("img").attr("src",styleUrl+"/styles/img/reduceIcon.png"); 
		   })
	   $(".addButton").bind("touchstart",function(e){ 
	   
	       $(this).find("img").attr("src",styleUrl+"/styles/img/addIconHover.png");
		   var goodsLastNum=$(this).parent().siblings(".goodsLastNum").find("b").html();
		   var goodsName=$(this).parent().siblings(".goodsName").html();
	       var peopleNum=Number($(this).siblings(".buyNumber").val()); 
		   if(peopleNum>=goodsLastNum){
			   $(this).siblings(".buyNumber").val(goodsLastNum);
			   commonTckBlack(goodsName+"仅剩"+goodsLastNum+"份");
			   return;
			   }
			peopleNum=Number(peopleNum)+1;
			$(this).siblings(".buyNumber").val(peopleNum);
			totalPrice();
		  },false)
	    $(".addButton").bind("touchend",function(e){
		   $(this).find("img").attr("src",styleUrl+"/styles/img/addIcon.png"); 
		   })
	   $(".buyNumber").change(function(){  
		   var goodsLastNum=$(this).parent().siblings(".goodsLastNum").find("b").html();
		   var goodsName=$(this).parent().siblings(".goodsName").html();
	       var peopleNum=Number($(this).val()); 
		   if(peopleNum>=goodsLastNum){
			   $(this).val(goodsLastNum);
			   commonTckBlack(goodsName+"仅剩"+goodsLastNum+"份");
			   return;
			   }
           if(isNaN(peopleNum)){
			  commonTckBlack("请输入数字");
			   $(this).val(1); 
		   }		   
		   if(peopleNum<0){
			   commonTckBlack("购买数量不能小于0");
			   $(this).val(0);
			   }
		  totalPrice();
		})
	
//改变剩余数量方法
//计算价格   
    function totalPrice(){ 
		//价格变动，总价跳动动画结束 
		 var buyPrice=0;var buyNum=0;  	 
		 var buyLength=$(".buyNumber").length;
		 for(var i=0;i<buyLength;++i){
			 buyNum=Number(buyNum)+Number($(".buyNumber").eq(i).val())
			 buyPrice=Number(buyPrice)+(Number($(".goodsPrice b").eq(i).html())*100*Number($(".buyNumber").eq(i).val())/100);
			 }
		//原始价格，不加优惠，不加抵扣，不加各种打折
		$("#selectNum").html(buyNum);
		$("#totalPrice b").html(buyPrice)//显示订单总价
	 };  
     totalPrice();
//点击事件
    if(wechat==false){
		$(".crowdDownLoad button").hide();	
	}
    $(".crowdDownLoad button").click(function(){
	 window.location.href="http://m.yamichefs.com";
	})
    $("#submit").click(function(){
		if(buyStop==true){
			if(localStorage.openId==""&&wechat==true){
			  alert("获取您的信息失败，请退出再重新打开本页面")
			}else{}
			return;
		}
	  var prodNum=[];var prodId=[];var isBuy=false;
      var buyNumLength=$(".buyNumber").length;
      for(var i=0;i<buyNumLength;++i){
	   prodId.push(crowdGoods[i][2]);
	   prodNum.push($(".buyNumber").eq(i).val());
	   var prodArray={
		   "prodId":prodId,
		   "prodNum":prodNum
		   }
	   localStorage.setItem("prodArray",JSON.stringify(prodArray));
       if(Number($(".buyNumber").eq(i).val()>0)){
		   isBuy=true;
		   }	  
	  }
	  if(isBuy==false){
		  commonTckBlack("请选择至少一份商品购买");
		  return;
		  }
	  if(wechat==false){   
      bridgeApp('bridgeLogin',{},function(response){
		  if(response.id==""||response.id==null||response.id=="undefined"||Number(response.id)==0||response.ID==""||response.ID=="undefined")return;
		  localStorage.token=response.token;	
				 if(response.userTel==""||response.userTel==null||response.userTel=="undefined"){
			   bridgeApp('bridgeBinding',{}, function(response){
				   if(response.data.userTel==""||response.data.userTel==null||response.data.userTel==undefined){
					   return;
				   }    
			        if(response.id){
				       userId=response.id;
				      }
			         else{
				       userId=response.ID;
				      }
			         gotoOrder(userId)
				  })
			  }
		  else{
			  if(response.id){
				 userId=response.id;
				 }
			  else{
				 userId=response.ID;
				 }
			  gotoOrder(userId)
			  } 		  
	      }) 
	  }
	  else{
	 window.location.href=initData.applyUrl;   
	 }
	})
	
function gotoOrder(userId){	
                localStorage.userId=userId;
			    bridgeApp('bridgePushVC',{'popNum':'0','vcType':'0','data':{"url":linkUrl+"content/crowd/toApply?crowdId="+initData.crowdId+"&userId="+userId} /*★★★★★需修改url,跳转到填写订单页面*/}, function(response) {	
				      })
	}